;(function ($) {
    /*
    * 保养评分
    * */
    $.upkeepScore = function (dispatchId, id, isBatchDeal, isWebsocket) {
        /* 添加模态框元素 */
        var model = $("#upkeepScore");
        if (!model.length) {
            $('body').append('<div id="upkeepScore" class="score" style="display:none">' +
                '<div class="box-body">' +
                    '<form class="form-horizontal engineerConfirmFrom" role="engineerConfirmFrom" method="post" enctype="multipart/form-data">' +
                        '<!-- (报修表id) -->' +
                        '<input type="hidden" class="confimrUpkeepId" name="upkeepId"><!-- 维修处理ID -->' +
                        '<input type="hidden" class="confirmDispatchId" name = "dispatchId">' +
                        '<!-- <input type="hidden" id="userId" name = "userId" value="${loginUser.id}"> --><!-- 设备ID -->' +
                        '<div class="form-group" style="padding-left: 0.3rem">' +
                            '<table class="grade-table" style="width: 100%">' +
                                '<tr>' +
                                    '<th>是否保养完<span class="text-red">*</span></th>' +
                                    '<td><label><input type="radio" class="flat-green" checked="checked" value="1" name="confirmStatus">是</label></td>' +
                                    '<td><label><input type="radio" class="flat-green" name="confirmStatus" value="2">否</label></td>' +
                                    '<td></td><td></td><td></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<th>服务总体评分<span class="text-red">*</span></th>' +
                                    '<td colspan="5"><div class="scores totalScore" name="score"></div></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<th>服务响应速度<span class="text-red">*</span></th>' +
                                    '<td colspan="5"><div class="scores speedScore" name="speedScore"></div></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<th>服务质量<span class="text-red">*</span></th>' +
                                    '<td colspan="5"><div class="scores qualityScore" name="qualityScore"></div></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<th>服务态度<span class="text-red">*</span></th>' +
                                    '<td colspan="5"><div class="scores attitudeScore" name="attitudeScore"></div></td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<th>发表评价</th>' +
                                    '<td colspan="5" style="padding-right: 0.7rem !important"><input class="form-control" type="text" name="comment"></td>' +
                                '</tr>' +
                            '</table>' +
                        '</div>' +
                    '</form>' +
                '</div>' +
                '<div class="box-footer text-center">' +
                    '<button type="button" class="btn save">保存</button>' +
                    '<button class="btn btn-default cancel">取消</button>' +
                '</div>' +
            '</div>');
            model = $("#upkeepScore");
            model.iziModal({
                title: "医院确认",
                headerColor: '#fff',
                radius: 0.4 * rem,
                overlayClose: false,
                theme: '',  // light
                autoOpen: false,
                zindex: 10010,
                width: 12 * rem,
                onOpening: function () {
                    model.find('input[type="radio"].flat-green').iCheck({
                        checkboxClass: 'icheckbox_flat-blue',
                        radioClass: 'iradio_flat-blue'
                    });
                },
                onClosed: function () {
                    model.find('.engineerConfirmFrom')[0].reset();
                    model.addClass('score');
                    model.find('.scores').raty('set', {score: 5});
                }
            });

            model.find('.scores').each(function () {
                $(this).raty({
                    path: basePath + '/plugins/raty/images',
                    hints: ['不满意','比较满意','一般','不太满意','满意'],
                    score: 5,
                    scoreName: $(this).attr('name')
                });
            });
        }

        model.find('.save').off().on('click', function (e) {
            var formData = new FormData(model.find('.engineerConfirmFrom')[0]);
            $.ajax({
                type: "POST",
                url: basePath + "/upkeep/confirmUpkeep",
                data: formData,
                dataType : "json",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data){
                    if(data.ret){
                        flavrShowByTime("操作成功",null,"success",null);
                        if (isBatchDeal) {
                            dealBatchDeal();
                        } else if (isWebsocket) {
                            model.iziModal('close',this);
                            messageObjArr[messageObjArr.index].isDoNow = true;
                            dealPushMessage();
                        } else {
                            model.iziModal('close',this);
                        }

                        loading(function () {
                            queryWarning();
                            for(var i = 1; i < 8; i++) {
                                queryWarningList(i);
                            }
                        });
                    }else{
                        flavrShowByTime("操作失败",null,"error");
                    }
                },
                failure: function(data){
                    flavrShowByTime("操作失败",null,"error");
                }
            });
            return false;
        });

        model.find('.cancel, .iziModal-button-close').off().click(function () {
            if (isWebsocket) {
                messageObjArr[messageObjArr.index].isDoNow = true;
                dealPushMessage();
            }
        });
        model.find('.cancel').off().click(function () {
            if (isBatchDeal) {
                dealBatchDeal();
            } else {
                model.iziModal('close');
            }
        });

        model.iziModal('open', this);
        model.find(".confirmDispatchId").val(dispatchId);
        model.find(".confimrUpkeepId").val(id);
    };
})(jQuery);